package com.study.gank.ui.activity

import android.os.Bundle
import android.view.MenuItem

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.databinding.ViewDataBinding
import com.study.gank.R

abstract class BaseBindingActivity<D : ViewDataBinding> : AppCompatActivity() {

    lateinit var mBinding: D
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = createDataBinding(savedInstanceState)
        initView()
    }

    abstract fun createDataBinding(savedInstanceState: Bundle?): D
    abstract fun initView()

    fun setupToolbar(toolbar: Toolbar) {
        toolbar.apply {
            title = ""
            setNavigationIcon(R.drawable.icon_back)
            setSupportActionBar(this)
        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            android.R.id.home -> onBackPressed()
        }
        return super.onOptionsItemSelected(item)
    }
}